#include "IFile.h"
#include "stdio.h"
/**
 * @brief
 * <bean interface="IFile" implemation="TextFile">
 *      <path name="" />
 *      <buffer copacity="" implemation = "StringBuffer" />
 * </bean>
 */
class SimpleConsole : public IFile {
public:
    virtual void onLoad(INode *node) {
        init();
        INode *child = node->childNode("buffer");
        if (child) {
            std::string implemation = child->getStr("implemation");
            buffer = (IBuffer*)IPlugin::loadPlugin(implemation.c_str());
            buffer->onLoad(child);
        }
    }
    virtual void onUnload() {
        if (buffer) {
            buffer->onUnload();
        }
    }
    virtual bool init() {
       return false;
    }
    virtual bool start() {
       return false;
    }
    virtual bool stop() {
       return false;
    }
    virtual bool destroy() {
        return false;
    }
    virtual void bind(IDevice *target) {

    }
    virtual IBuffer *get() {
        fread(buffer->content(),buffer->copacity(),1,stdin);
        buffer->resize(buffer->copacity());
        return buffer;
    }
    virtual void put(IBuffer *buf) {
        fwrite(buf->content(),buf->size(),1,stdout);
    }
    SimpleConsole() {
        buffer = NULL;
    }

    IBuffer *buffer;
};

REG_PLUGIN(SimpleConsole);
